<?php
require_once DIR_APPLICATION . 'controller/abstract.php';
use EasyWeChat\Factory;

class ControllerUserLogin extends AppController {

	public function index() {
            if (isset($this->request->get['code'])) {
                  $code = trim($this->request->get['code']);
                  $this->load->model('setting/app');
                  $appConfig = $this->session->data['appConfig'];
                  $app = $this->model_setting_app->miniApp($appConfig);
                  
                  try {
                        $result = $app->auth->session($code);
                        if (!$result) {
                              throw new Exception("登陆失败！");
                        }
                        $this->jsonSuccess($result);
                  } catch(Exception $e) {
                        $error = $e->getMessage();
                  }
                  $this->jsonError([], '登陆失败！');
            }
            $this->jsonError([], '登陆失败！');
      }

}